package com.example.chang.law_doc.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.chang.law_doc.R;
import com.example.chang.law_doc.entity.LibraryItemData;

import java.util.List;

/**
 * Created by chang on 2018/4/13.
 * 项目描述：
 */

public class LibraryItemAdapter extends BaseAdapter{
    private Context mContext;
    private List<LibraryItemData> mList;

    private LayoutInflater inflater;
    private LibraryItemData data;

    public LibraryItemAdapter(Context mContext, List<LibraryItemData> mList){
        this.mContext = mContext;
        this.mList = mList;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mList.size();

    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        //第一次加载
        if (view == null) {
            viewHolder = new ViewHolder();
            view = inflater.inflate(R.layout.activity_library_item, null);
            viewHolder.tv_library_title = view.findViewById(R.id.tv_library_title);
            viewHolder.tv_youxiao = view.findViewById(R.id.tv_youxiao);
            viewHolder.tv_xiugai = view.findViewById(R.id.tv_xiugai);
            viewHolder.tv_library_content=view.findViewById(R.id.tv_library_content);
            viewHolder.tv_library_main=view.findViewById(R.id.tv_library_main);
            viewHolder.tv_library_number=view.findViewById(R.id.tv_library_number);
            //设置缓存
            view.setTag(viewHolder);
        } else {
            viewHolder = (LibraryItemAdapter.ViewHolder) view.getTag();
        }
        data = mList.get(i);
        viewHolder.tv_library_title.setText(data.getTitle());
        viewHolder.tv_youxiao.setText(data.getYouxiao());
        viewHolder.tv_youxiao.setText(data.getXiugai());
        viewHolder.tv_library_content.setText(data.getContent());
        viewHolder.tv_library_main.setText(data.getMain());
        viewHolder.tv_library_number.setText(data.getNumber());
        return view;
    }
    class ViewHolder {
        private TextView tv_library_title;
        private TextView tv_youxiao;
        private TextView tv_xiugai;
        private TextView tv_library_content;
        private TextView tv_library_main;
        private TextView tv_library_number;


    }
}
